import util from "../../../../utils/util";
const app = getApp();
var num = {};
Page({

    /**
     * 页面的初始数据
     */
    data: {
        city: "深圳",
        project: ["项目", "个人缴纳(元）", "单位缴纳(元）"],
        scroll: false,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.setData({
            computeData: JSON.parse(options.computeData),
        });

        util.getUrl(app.globalData.url).then(res => {
            util.request("zhuanti.php", {
                action: "wuxianyijin",
                citycode: this.data.computeData.city,
                type: this.data.computeData.type,
            }, ).then(res => {
                if (res.data.message == "success") {
                    num = res.data.data.ss;
                    this.computePayment(this.data.computeData);
                }
            });
        });
    },

    computePayment(computeData) {
        let yanglao = {
            per: computeData.baseNum * num.yanglao.per,
            com: computeData.baseNum * num.yanglao.com,
        };
        let gongshang = {
            per: computeData.baseNum * num.gongshang.per,
            com: computeData.baseNum * num.gongshang.com,
        };;
        let shengyu = {
            per: computeData.baseNum * num.shengyu.per,
            com: computeData.baseNum * num.shengyu.com,
        };;
        let yiliao = {
            per: computeData.baseNum * num.yiliao.per,
            com: computeData.baseNum * num.yiliao.com,
        };;
        let shiye = {
            per: computeData.baseNum * num.shiye.per,
            com: computeData.baseNum * num.shiye.com,
        };;

        let personSum = parseFloat(yanglao.per) + parseFloat(gongshang.per) + parseFloat(shengyu.per) + parseFloat(yiliao.per) + parseFloat(shiye.per);
        let comidSum = parseFloat(yanglao.com) + parseFloat(gongshang.com) + parseFloat(shengyu.com) + parseFloat(yiliao.com) + parseFloat(shiye.com);
        let paymentAll = personSum + comidSum;

        this.setData({
            details: [
                { name: '养老保险', person: yanglao.per.toFixed(2), comid: yanglao.com.toFixed(2) },
                { name: '医疗保险', person: gongshang.per.toFixed(2), comid: gongshang.com.toFixed(2) },
                { name: '工伤保险', person: shengyu.per.toFixed(2), comid: shengyu.com.toFixed(2) },
                { name: '生育保险', person: yiliao.per.toFixed(2), comid: yiliao.com.toFixed(2) },
                { name: '失业保险', person: shiye.per.toFixed(2), comid: shiye.com.toFixed(2) },
            ],
            personSum: personSum.toFixed(2),
            comidSum: comidSum.toFixed(2),
            paymentAll: paymentAll.toFixed(2),
        });
        if (computeData.payment && computeData.proportion && computeData.payBaseNum) {
            this.data.details.push({
                name: "公积金",
                person: (computeData.payBaseNum * computeData.proportion * 0.01).toFixed(2),
                comid: (computeData.payBaseNum * computeData.proportion * 0.01).toFixed(2),
            });
            this.data.personSum = parseFloat(this.data.personSum) + (computeData.payBaseNum * computeData.proportion * 0.01);
            this.data.comidSum = parseFloat(this.data.comidSum) + (computeData.payBaseNum * computeData.proportion * 0.01);
            this.data.paymentAll = this.data.personSum + this.data.comidSum;
            this.setData({
                details: this.data.details,
                personSum: this.data.personSum.toFixed(2),
                comidSum: this.data.comidSum.toFixed(2),
                paymentAll: this.data.paymentAll.toFixed(2),
            });
        }


    },

    /**
     * 用户点击右上角分享
     */
})